package cn.tedu.spring.tools;

import cn.tedu.spring.user.User;
import cn.tedu.spring.user.UserConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.sql.SQLOutput;

/**
 * Author：程Sir
 * Name： SpringTest01
 * Content:
 */
public class JdbcSpringTest {

    AnnotationConfigApplicationContext acac;
    @Test
    public void test(){
        // 2. 获取容器中的指定对象
        JdbcSpring jdbcSpring = acac.getBean("jdbcSpring",JdbcSpring.class);
        System.out.println(jdbcSpring);
    }

    @Test
    public void test1(){
        // 2. 获取容器中的指定对象
        JdbcSpringDI jdbcSpring = acac.getBean("jdbcSpringDI",JdbcSpringDI.class);
        System.out.println(jdbcSpring);
        System.out.println(jdbcSpring.getEnvironment().getProperty("jdbc.driver"));
        System.out.println(jdbcSpring.getEnvironment().getProperty("jdbc.url"));
        System.out.println(jdbcSpring.getEnvironment().getProperty("db.username"));
        System.out.println(jdbcSpring.getEnvironment().getProperty("db.password"));
        System.out.println(jdbcSpring.getEnvironment().getProperty("db.maxActive"));
        System.out.println(jdbcSpring.getEnvironment().getProperty("db.initialSize"));
    }

    @Before
    public void init(){
        // 1.实例化spring容器
        acac = new AnnotationConfigApplicationContext(SpringConfig.class);
        System.out.println("spring容器初始化....");

    }
    @After
    public void destory(){
        // 3. 关闭容器
        acac.close();
    }

}
